package com.zenkeeuk.bookcamera.client.android.book;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class BookCommentsAdapter extends BaseAdapter {
	private static final String CLASSTAG = BookReviewAdapter.class.getSimpleName();
    private final Context context;
    private final List<DoubanBookComment> reviews;

    public BookCommentsAdapter(Context context, List<DoubanBookComment> reviews) {
        this.context = context;
        this.reviews = reviews;
        Log.v(CLASSTAG, " " + " reviews size - " + this.reviews.size());
    }

    public int getCount() {
        return this.reviews.size();
    }

    public Object getItem(int position) {
        return this.reviews.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
    	DoubanBookComment review = this.reviews.get(position);
        return new CommentListView(this.context, review);
    }
    
    private final class CommentListView extends LinearLayout {
    	private TextView title;
        private TextView author;
        private TextView summary;
        private TextView rating;

        public CommentListView(Context context, DoubanBookComment review) {

            super(context);
            setOrientation(LinearLayout.VERTICAL);

            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
            params.setMargins(5, 3, 5, 0);
            

            this.title = new TextView(context);
            this.title.setText(review.getTitle());
            this.title.setTextSize(16f);
            this.title.setTextColor(Color.WHITE);
            this.addView(this.title, params);

            this.rating = new TextView(context);
            this.rating.setText(String.valueOf(review.getRating()));
            this.rating.setTextSize(16f);
            this.rating.setTextColor(Color.YELLOW);
            this.addView(this.rating, params);

            this.author = new TextView(context);
            this.author.setText(String.valueOf(review.getAuthor()));
            this.author.setTextSize(16f);
            this.author.setTextColor(Color.WHITE);
            this.addView(this.author, params);
            
            this.summary = new TextView(context);
            this.summary.setText(String.valueOf(review.getSummary()));
            this.summary.setTextSize(16f);
            this.summary.setTextColor(Color.WHITE);
            this.addView(this.summary, params);
        }
    }


}
